feat: implement secure user authentication with JWT, bcrypt, and Prisma#76
Merged
gelluisaac merged 3 commits intonexoraorg:developfrom Oct 4, 2025
Merged
Conversation
Signed-off-by: Ibrahim <ajiboseibrahim12@gmail.com>
Contributor
Author
|
i am sorry for the delay. i had issue with my laptop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
implement secure user authentication
Summary
This PR introduces a robust, secure authentication system for the backend
It enables user registration, login, and access token refresh functionality using JWT, bcrypt, Zod, and Prisma ORM
Implementation Details
Core Features
/authendpointsenum Role { user, admin }Database Models (Prisma)
New Files Added
src/controllers/authController.ts– Core authentication logicsrc/utils/password.ts– Password hashing/comparisonsrc/utils/jwt.ts– JWT generation and validationsrc/routes/auth.ts– Auth routes with rate limiterprisma/schema.prisma– Updated schema with relations and enumssrc/prisma/client.ts– Shared Prisma client instanceSetup & Migration Instructions
Before running or testing the API, ensure your environment is ready:
Install dependencies
Set up your .env file
Create a .env file in the backend/ directory with the following variables (use secure random secrets in production):
Ensure .env and prisma/dev.db are listed in .gitignore*
Generate Prisma client
Apply database migrations
pnpm prisma migrate dev --name init
Start the development server
pnpm run dev
The backend will start on:
http://localhost:5000
Testing Instructions
curl -X POST http://localhost:5000/api/auth/register
-H "Content-Type: application/json"
-d '{"email": "test@example.com", "password": "Password123!"}'
Expected Response:
{ "message": "User registered", "userId": "<uuid>" }Expected Response:
{ "accessToken": "<jwt_access_token>", "refreshToken": "<refresh_token>" }Copy the refreshToken, it will be needed in the next step
Expected Response:
{ "accessToken": "<new_jwt_access_token>" }Developer Notes
Passwords are hashed using bcrypt (never stored in plaintext).
Tokens are signed and verified using .env secrets.
Refresh tokens are stored hashed in the database for security.
Rate limiting is applied to prevent brute-force attacks.
i had to include one more file not in the requirement of the task so i could be able to use prisma
Prisma handles database schema and migrations.